package com.vmj.test.example.array;

import com.vmj.test.example.MyObject;

/**
 * Created by yangshoujun on 2017/9/9 下午2:41.
 */
public class ArrayObj {

    public static void main(String[] args) {

//        byte b = 10;
//        new ArrayObj().testObjArr(b);
//        new ArrayObj().test(10);
        new ArrayObj().testMultiArray(4,2);
    }

    public void test(int n) {
        byte[] b = new byte[n];
        for(byte i = 0;i < b.length;i++) {
            b[i] = (byte)(i+1);
        }

        for(byte d : b) {
            System.out.print(d);
            System.out.println('\t');
        }
        System.out.println();
    }

    public void testObjArr(byte n) {
        MyObject[] a = new MyObject[n];
        for(byte i = 0;i < n;i++) {
            MyObject o = new MyObject();
            o.instanceVar = i+1;
            a[i] = o;
        }

        for(MyObject o : a) {
            System.out.println(o.instanceVar);
        }
    }

    public void testMultiArray(int... n) {
        int n1 = n[0];
        int n2 = n[1];
        int[][] arr = new int[n1][n2];
        for(byte i = 0;i < n1;i++) {

            int[] a = new int[n2];
            for(byte j = 0;j < n2;j++) {
                a[j] = i + j + 1;
            }

            arr[i] = a;
        }

        for(byte i = 0;i < n1;i++) {

            int[] a = arr[i];
            for(byte j = 0;j < n2;j++) {
                System.out.print(a[j]);
                System.out.print('\t');
            }

            System.out.println();
        }
    }

}
